﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConquerServer_Basic
{
    public class NpcSpawnPacket : IClassPacket, INpc, IMapObject
    {
        private byte[] Packet;
        private ushort m_MapID;

        public NpcSpawnPacket()
        {
            Packet = new byte[20];
            PacketBuilder.WriteUInt16(20, Packet, 0);
            PacketBuilder.WriteUInt16(2030, Packet, 2);
        }
        public uint UID
        {
            get { return BitConverter.ToUInt32(Packet, 4); }
            set { PacketBuilder.WriteUInt32(value, Packet, 4); }
        }
        public ushort X
        {
            get { return BitConverter.ToUInt16(Packet, 8); }
            set { PacketBuilder.WriteUInt16(value, Packet, 8); }
        }
        public ushort Y
        {
            get { return BitConverter.ToUInt16(Packet, 10); }
            set { PacketBuilder.WriteUInt16(value, Packet, 10); }
        }
        public ushort Type
        {
            get { return BitConverter.ToUInt16(Packet, 12); }
            set { PacketBuilder.WriteUInt16(value, Packet, 12); }
        }
        public ConquerAngle Facing
        {
            get { return (ConquerAngle)Packet[14]; }
            set { Packet[14] = (byte)value; }
        }
        public uint StatusFlag
        {
            get { return BitConverter.ToUInt32(Packet, 16); }
            set { PacketBuilder.WriteUInt32(value, Packet, 16); }
        }
        public ushort MapID { get { return m_MapID; } set { m_MapID = value; } }
        public MapObjectType MapObjType { get { return MapObjectType.Npc; } }
        public object Owner { get { return this; } }
        public void SendSpawn(GameClient Client, bool Ignore)
        {
            if (Client.Screen.Add(this) || Ignore)
            {
                Client.Send(Packet);
            }
        }
        public void SendSpawn(GameClient Client)
        {
            SendSpawn(Client, false);
        }

        public byte[] Serialize()
        {
            return Packet;
        }
        public void Deserialize(byte[] Bytes)
        {
            Packet = Bytes;
        }
    }
}
